package com.leetcode.algorithm.y22.m07;

/**
 * 896. 单调数列
 * 
 * https://leetcode.cn/problems/monotonic-array/
 * 
 * @author jie.deng
 *
 */
class Question0896Solution01 {

	public boolean isMonotonic(int[] nums) {
		return isAsc(nums) || isDesc(nums);
	}

	private boolean isDesc(int[] nums) {
		int len = nums.length;
		for (int i = 1; i < len; i++) {
			if (nums[i - 1] < nums[i]) {
				return false;
			}
		}
		return true;
	}

	private boolean isAsc(int[] nums) {
		int len = nums.length;
		for (int i = 1; i < len; i++) {
			if (nums[i - 1] > nums[i]) {
				return false;
			}
		}
		return true;
	}

}